<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of AbstractData
 *
 * @author mateusz.ledzewicz
 */
abstract class AbstractData {
    
    protected $data;
    protected $dataInternet;
    //put your code here
    public function getData()
    {
        return $this->data;
    }
    
     public function getValue($param, $key)
    {
        if(in_array($param->param, 
                array(Param::openPrice, Param::highPrice, Param::lowPrice, Param::closePrice, Param::volume)))
        {
            return $this->dataInternet[$key][AbstractGet::$mapper[$param->param]];
        }
        
        switch($param->param)
        {
            case Param::minmaxChange:
                return $this->dataInternet[$key][AbstractGet::$mapper[Param::highPrice]]-$this->dataInternet[$key][AbstractGet::$mapper[Param::lowPrice]];
            break;
            case Param::opencloseChange:
                return $this->dataInternet[$key][AbstractGet::$mapper[Param::closePrice]]-$this->dataInternet[$key][AbstractGet::$mapper[Param::openPrice]];
            
            break;
            case Param::currency:
                return (float) $this->moneyInternet[$this->dataInternet[$key][AbstractGet::$mapper[AbstractGet::date]]];
            break;
            case Param::growBefDay:
                return $this->dataInternet[$key][AbstractGet::$mapper[Param::closePrice]]-$this->dataInternet[$key+$param->value][AbstractGet::$mapper[Param::closePrice]];
            break;
            case Param::growBasicBefDay:
                $grow = $this->dataInternet[$key][AbstractGet::$mapper[Param::closePrice]]-$this->dataInternet[$key+$param->value][AbstractGet::$mapper[Param::closePrice]];
                $value = 1;
                
                if($grow > 0)       $value = 1;
                else if($grow == 0) $value = 0;
                else                $value = -1;
                return $value;
            break;
            case Param::candle:
                $openclose = $this->dataInternet[$key][AbstractGet::$mapper[Param::closePrice]]-$this->dataInternet[$key][AbstractGet::$mapper[Param::openPrice]];
                $minmax = $this->dataInternet[$key][AbstractGet::$mapper[Param::highPrice]]-$this->dataInternet[$key][AbstractGet::$mapper[Param::lowPrice]];
                if($minmax == 0)
                    return 1;
                return abs($openclose/$minmax);
            break;
            
        }
        throw new Exception("Bad param in getValue");
        
    }
    
    public function getIn($param, $key)
    {
        if($param->param == Param::currency)
            return $this->getValue ($param, $key);
        
        switch($param->type)
        {
            case Param::typeValue:
                 return $this->getValue($param, $key);
            break;
            case Param::typeAvg:
                $value = 0;
                for($i=0; $i< $param->value; $i++){
                     $value += $this->getValue($param, $key+$i);
                } 
                return $value/$param->value;
            break;
            case Param::typeGrow:
                  return $this->getValue($param, $key)-$this->getValue($param, $key+$param->value);
            break;
        }
    }
    
    
    abstract protected function prepareData();
}

?>
